package scala.test_types

import scala.reflect.runtime.universe.MethodType

/**
 * @author 黄海峰 2021/4/15 14:51
 * */
object UnifiedTypes {
  /**
   * Any is the supertype of all types, also called the top type.
   * It defines certain universal methods such as equals, hashCode, and toString.
   * Any has two direct subclasses: AnyVal and AnyRef.
   *
   * AnyVal represents value types.
   * There are nine predefined value types and they are non-nullable:
   * Double, Float, Long, Int, Short, Byte, Char, Unit, and Boolean
   * eg:Unit is a value type which carries no meaningful information.
   *
   * AnyRef represents reference types.
   * All non-value types are defined as reference types.
   * Every user-defined type in Scala is a subtype of AnyRef.
   * If Scala is used in the context of a Java runtime environment,
   * AnyRef corresponds to java.lang.Object.
   */
  def main(args: Array[String]): Unit = {
    val list: List[Any] = List(
      "atr string",
      733,
      'c',
      78.98,
      true,
      () => "hello,dean"
    )
    list.foreach(item => {
      print(item + "，")
    })

    println("")

    // 无法获取匿名函数类型 scala.test_types.BaseTypes$$$Lambda$3/1837543557@6e3c1e69
    list.foreach {
      case item@(_: MethodType) => println("方法类型：" + item)
      case item@(_: String) => println("字符串类型：" + item)
      case item => println("其他类型：" + item)
    }

    val emptyList: List[String] = List()
    emptyList.foreach(item => {
      print(item)
    })
    println(emptyList.isEmpty)
    println(emptyList.toString())

    val x: Long = 987654321
    println(x)
    val y: Float = x // 9.8765434E8 (note that some precision is lost in this case)
    println(y)
    val face: Char = '☺'
    println(face)
    val number: Int = face // 9786
    println(number)

    val userMap: Map[String, String] = Map()
    println(userMap.get("1"))
  }


}
